package com.skytech.chatim.sky.xmlapi;

import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;

/**
 * Created by Vega on 2015/1/7.
 */
public class WbxClientUtils {
    public static String doc2string(Document document) {
        return doc2string(document, false);
    }

    
    public static String doc2string(Document document, boolean suppressDeclaration) {
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            OutputFormat format = new OutputFormat("", false, "UTF-8");
            format.setSuppressDeclaration(suppressDeclaration);
            XMLWriter writer = new XMLWriter(out, format);
            writer.write(document);
            return out.toString("UTF-8");
        } catch (IOException e) {
            return "";
        }
    }

    public static SimpleDateFormat getWebExXmlApiDateFormat() {
        return new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    }

    public static String getWebExUrlApiEndPoint(String siteName) {
        return "https://" + siteName + ".webex.com.cn/" + siteName;
    }
}
